package com.chao.tlias.filter;
/**
 * 过滤器设置
 */

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")
@Slf4j
public class DemoFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {//初始化方法，服务器开启时调用，只运行一次
        log.info("init 初始化方法....");
    }

    /**
     * 拦截请求，执行多次
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截到了请求");
        //放行请求
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {//销毁方法，服务器关闭时调用，只运行一次
        log.info("destroy 销毁方法.....");
    }
}
